// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/equipment/api/AssetTypePropertyApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/equipment/model/AssetTypePropertyListReq'
import AddClass from '@api/equipment/model/AssetTypePropertyOperateReq'
import DelClass from '@api/equipment/model/AssetTypePropertyReq'
import BaseClass from '@api/equipment/model/AssetTypePropertyDto'

const EditClass = AddClass

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']
const BASE = [BaseClass, 'assetTypePropertyDto']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  validParam(param) {
    return param.assetTypeId
  },
  async getList(param, TIP = '查询列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'queryAssetTypePropertyList', DTO)
    return [resp.comQuery.totalCount, resp.assetTypePropertyDto || []]
  },

  // —————————————————————————————— 增 —————————————————————————————— //

  async add(one, TIP = '新增') {
    const DTO = CORE.grpcDTO(AddClass, one, BASE)
    await CORE.grpc(TIP, CLIENT, 'insertAssetTypeProperty', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 改 —————————————————————————————— //

  async edit(one, TIP = '修改') {
    const DTO = CORE.grpcDTO(EditClass, one, BASE)
    await CORE.grpc(TIP, CLIENT, 'updateAssetTypeProperty', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 删 —————————————————————————————— //

  async del({ id }, TIP = '删除') {
    const DTO = CORE.grpcDTO(DelClass, { ids: [id] })
    await CORE.grpc(TIP, CLIENT, 'deleteAssetTypeProperty', DTO)
    return CORE.grpcOK(TIP)
  },
}
